package com.actions.bluetoothbox2.util;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.actions.bluetoothbox2.R;

/**
 * Created by liuyong on 2017/12/26.
 */

public class PopColorSelectAdapter extends BaseAdapter {


    Context context;
    int imgID[] = new int[]{R.drawable.ic_color1, R.drawable.ic_color2, R.drawable.ic_color3, R.drawable.ic_color4,
            R.drawable.ic_color5, R.drawable.ic_color6, R.drawable.ic_color7, R.drawable.ic_color8, R.drawable.ic_color9,
            R.drawable.ic_color10, R.drawable.ic_color11, R.drawable.ic_color12, R.drawable.ic_color13, R.drawable.ic_color14,
            R.drawable.ic_color15};
    int imgID_select[] = new int[]{R.drawable.ic_color1_select, R.drawable.ic_color2_select, R.drawable.ic_color3_select,
            R.drawable.ic_color4_select, R.drawable.ic_color5_select, R.drawable.ic_color6_select, R.drawable.ic_color7_select,
            R.drawable.ic_color8_select, R.drawable.ic_color9_select, R.drawable.ic_color10_select, R.drawable.ic_color11_select,
            R.drawable.ic_color12_select,R.drawable.ic_color13_select,R.drawable.ic_color14_select,R.drawable.ic_color15_select};
    boolean[] isCheck;

    public PopColorSelectAdapter(Context context, boolean[] isCheck) {
        this.context = context;
        this.isCheck = isCheck;
    }

    @Override
    public int getCount() {
        return imgID.length;
    }

    @Override
    public Object getItem(int position) {
        return imgID[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_color_select, parent, false);
        }
        ImageView img_ico = (ImageView) convertView.findViewById(R.id.img_ico);
//        TextView tv_zdy = (TextView) convertView.findViewById(R.id.tv_zdy);
        if (isCheck[position]) {
            img_ico.setImageResource(imgID_select[position]);
        } else {
            img_ico.setImageResource(imgID[position]);
        }
//        if (position == imgID.length - 1) {
//            tv_zdy.setVisibility(View.VISIBLE);
//        }
        return convertView;
    }
}
